﻿using IdentityServer4.Models;
using IdentityServer4.Stores;

namespace MyWeb.Ids4Authorization
{
    /// <summary>
    /// 检索客户端配置
    /// </summary>
    public class ClientStore : IClientStore
    {
        /// <summary>
        /// 按id查找客户端
        /// </summary>
        /// <param name="clientId"></param>
        /// <returns></returns>
        public async Task<Client> FindClientByIdAsync(string clientId)
        {
            #region 用户名密码
            var memoryClients = OAuthData.GetClients();
            if (memoryClients.Any(oo => oo.ClientId == clientId))
            {
                return memoryClients.FirstOrDefault(oo => oo.ClientId == clientId);
            }
            #endregion

            #region 通过数据库查询Client 信息
            return GetClient(clientId);
            #endregion
        }

        private Client GetClient(string client)
        {
            //TODO 根据数据库查询
            return null;
        }
    }
}
